package com.gouda.web.exception;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: souu
 * Date: 15-3-26
 * Time: 下午4:28
 * To change this template use File | Settings | File Templates.
 */
public enum ErrorCode {

    SUCCESS("1", "success"),

    EC_400000("-400000", "消息体格式错误"),

    EC_400001("-400001", "服务器内部错误"),

    EC_400004("-400004", "请求参数不正确"),

    EC_400005("-400005", "未登录"),

    EC_400006("-400006", "权限错误");

    private String result;
    private String message;

    private ErrorCode(String code, String message) {
        this.result = code;
        this.message = message;
    }

    private static final Map<String, ErrorCode> interToEnum = new HashMap<String, ErrorCode>();

    static {
        for (ErrorCode type : ErrorCode.values()) {
            interToEnum.put(type.getCode(), type);
        }
    }

    public String getCode() {
        return result;
    }

    public void setCode(String code) {
        this.result = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public static ErrorCode fromCode(String code) {
        return interToEnum.get(code);
    }
}
